/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */

/*
 * PlayG.java
 *
 * Created on 10-11-2011, 01:45:54
 */
package swing;

import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import swing.ConfigVariable;
import config.MyConnection;
import java.awt.Color;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.File;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.ArrayList;
import javax.swing.AbstractButton;
import javax.swing.Icon;
import javax.swing.JOptionPane;

/**
 *
 * @author ADMIN
 */
public class PlayGame extends javax.swing.JFrame {

    private Icon AnswerFalse = new javax.swing.ImageIcon(getClass().getResource("/images/bgAnserCorect.png"));
    private Icon bgAnswer = new javax.swing.ImageIcon(getClass().getResource("/images/bgAnser.png"));
    Image icon = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/images/question_mark_icon_blueglow.png"));
    private Connection connect = null;
    private int Amount = 0;
    private int CountFlip = 13;
    private int Count = 0;
    private int MinusMoney = 0;
    private int Countdown = 100;
    private int idQuestion = 0;
    private String Answer = "";
    private boolean testChoice = false;
    private boolean testAnswer = false;
    private boolean DoubleDip = false;
    private ResultSet rs = null;
    private boolean checkRd = true;
    private int valueId = 0;
    private int number = 0;
    ArrayList list = new ArrayList();

    /** Creates new form PlayG */
    public PlayGame() {
        initComponents();
        this.setAlwaysOnTop(true);
        this.setIconImage(icon);
        lbName.setText("Wellcome : " + swing.ConfigVariable.Username);
        config.Config.loadConfig();
        if (!MyConnection.connect(config.Config.getProperty(config.Config.CONFIG_SERVERNAME),
                config.Config.getProperty(config.Config.CONFIG_PORTNUMBER),
                config.Config.getProperty(config.Config.CONFIG_DATABASENAME),
                config.Config.getProperty(config.Config.CONFIG_SERVERUSERNAME),
                config.Config.getProperty(config.Config.CONFIG_SERVERPASSWORD))) {
            JOptionPane.showMessageDialog(null, "Can not connect to server", "Message", JOptionPane.ERROR_MESSAGE);
            swing.Config cf = new swing.Config(null, true);
            cf.setVisible(true);
            new PlayGame().setVisible(false);
        }
        getId();
        LoadQuestion();
        SumAmount();
        this.setLocationRelativeTo(null);
        btnLeaveGame.setEnabled(false);
        btnNext.setEnabled(false);
    }
    //Put up Prize money

    public void SetPrizeMoney() {
        if (Count == 0) {
            lbPrizeMoney.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/prizemoney1.png")));
        } else if (Count == 1) {
            lbPrizeMoney.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/prizemoney2.png")));
        } else if (Count == 2) {
            lbPrizeMoney.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/prizemoney3.png")));
        } else if (Count == 3) {
            lbPrizeMoney.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/prizemoney4.png")));
        } else if (Count == 4) {
            lbPrizeMoney.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/prizemoney5.png")));
        } else if (Count == 5) {
            lbPrizeMoney.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/prizemoney6.png")));
        } else if (Count == 6) {
            lbPrizeMoney.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/prizemoney7.png")));
        } else if (Count == 7) {
            lbPrizeMoney.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/prizemoney8.png")));
        } else if (Count == 8) {
            lbPrizeMoney.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/prizemoney9.png")));
        } else if (Count == 9) {
            lbPrizeMoney.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/prizemoney10.png")));
        } else if (Count == 10) {
            lbPrizeMoney.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/prizemoney11.png")));
        } else if (Count == 11) {
            lbPrizeMoney.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/prizemoney12.png")));
        } else if (Count == 12) {
            lbPrizeMoney.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/prizemoney13.png")));
        }
    }

    private void LoadQuestion() {
        rdoA.setBackground(Color.BLACK);
        rdoB.setBackground(Color.BLACK);
        rdoC.setBackground(Color.BLACK);
        rdoD.setBackground(Color.BLACK);
        config.Config.loadConfig();
        connect = MyConnection.getConn();
        if (Count < CountFlip) {
            SetPrizeMoney();
            Countdown = 100;
            //Set text for count question and remove all radio button selection
            lbMinusMoney.setText("" + MinusMoney);
            buttonGroup1.clearSelection();
            getQuestions();
        } else {
            new ShowMessageDialog(null, true, "You've answered all these questions in turn.", "Message", ShowMessageDialog.MESSAGE);
            SetFinalInformation();
        }
    }
    //Add Item Listener for all radio button

    public void randomQuestions() {
        try {
            config.Config.loadConfig();
            connect = MyConnection.getConn();
            String rdId = "SELECT TOP 1[Id] FROM Question a ORDER BY NEWID()";
            ResultSet rsId = MyConnection.resultSet(rdId);
            rsId.next();
            valueId = rsId.getInt(1);
        } catch (SQLException ex) {
            Logger.getLogger(PlayGame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void checkRandom() {
        if (!list.contains(valueId)) {
            checkRd = true;
            return;
        }
        if (list.contains(valueId)) {
            checkRd = false;
            return;
        }
    }

    public void addId() {
        if (checkRd == true) {
            list.add(valueId);
        }
        if (checkRd == false) {
            for (int i = 0; i < 20; i++) {
                randomQuestions();
                if (!list.contains(valueId)) {
                    list.add(valueId);
                    return;
                }
            }
        }
    }

    public void getId() {
        for (int i = 0; i < 20; i++) {
            randomQuestions();
            checkRandom();
            addId();
        }
    }
    public void getQuestions() {

        number++;
        String change = String.valueOf(list.get(number));
        idQuestion = Integer.parseInt(change);

        try {
            config.Config.loadConfig();
            connect = MyConnection.getConn();
            String sql = "select * from Question where Id=" + idQuestion + "";
            rs = MyConnection.resultSet(sql);
            rs.next();
            txtQuestion.setText(rs.getString("Content"));
            rdoA.setText(rs.getString("AnswerA"));
            rdoB.setText(rs.getString("AnswerB"));
            rdoC.setText(rs.getString("AnswerC"));
            rdoD.setText(rs.getString("AnswerD"));
            swing.ConfigVariable.RightAnswer = rs.getString("CorrectAnswer");
        } catch (SQLException ex) {
            Logger.getLogger(PlayGame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void SetItemStateChanged() {
        ItemListener IL = new ItemListener() {

            public void itemStateChanged(ItemEvent itemEvent) {
                AbstractButton aButton = (AbstractButton) itemEvent.getSource();
                int state = itemEvent.getStateChange();
                if (state == ItemEvent.SELECTED) {
                    Answer = aButton.getText();
                    Answer = Answer.substring(3, Answer.length());
                }
            }
        };
        rdoA.addItemListener(IL);
        rdoB.addItemListener(IL);
        rdoC.addItemListener(IL);
        rdoD.addItemListener(IL);
    }
    //Sum amount

    private void SumAmount() {
        if (Count < 8 && Count >= 1) {
            Amount *= 2;
        }
        if (Count == 8) {
            Amount = 12500;
        }
        if (Count >= 9 && Count < 12) {
            Amount *= 2;
        }
        if (Count == 12) {
            Amount = 500000;
        }
        lbAmount.setText(Integer.toString(Amount));
    }

    //Store amounts are subtracted
    public void MinusMoney() {
        if (Count <= 2) {
            MinusMoney = 0;
            lbMinusMoney.setText(Integer.toString(MinusMoney));
        } else if (Count == 3) {
            MinusMoney = Amount / 2;
            lbMinusMoney.setText(Integer.toString(MinusMoney));
        } else if (Count > 3 && Count < 8) {
            MinusMoney = (Amount * 2) - (100 + Amount);
            lbMinusMoney.setText(Integer.toString(MinusMoney));
        } else if (Count >= 8 && Count <= 13) {
            MinusMoney = (Amount * 2) - (3200 + Amount);
            lbMinusMoney.setText(Integer.toString(MinusMoney));
        }
    }

    public void SetFinalInformation() {
        ConfigVariable.TotalQuestion = Count;
        ConfigVariable.MinusMoney = MinusMoney;
        ConfigVariable.TotalMoney = Amount;
        new PlayStatistic(null, true).setVisible(true);
        this.dispose();
    }

    public void Help5050() {
        int flag = 0;
        String TextRB1 = rdoA.getText();
        String TextRB2 = rdoB.getText();
        String TextRB3 = rdoC.getText();
        String TextRB4 = rdoD.getText();
        if (!TextRB1.equals(ConfigVariable.RightAnswer) && flag < 2) {
            rdoA.setText("");
            flag++;
        }
        if (!TextRB2.equals(ConfigVariable.RightAnswer) && flag < 2) {
            rdoB.setText("");
            flag++;
        }
        if (!TextRB3.equals(ConfigVariable.RightAnswer) && flag < 2) {
            rdoC.setText("");
            flag++;
        }
        if (!TextRB4.equals(ConfigVariable.RightAnswer) && flag < 2) {
            rdoD.setText("");
            flag++;
        }
    }

    public void RighAnswer() {
        if (Count < 13) {
            new ShowMessageDialog(null, true, "CorectAnswer", "Message", ShowMessageDialog.MESSAGE);
            SumAmount();
        }
        if (Count == 12) {
            new ShowMessageDialog(null, true, "You are Winner !!!! ", "Message", ShowMessageDialog.MESSAGE);
            SumAmount();
            ConfigVariable.TotalQuestion = 13;
            ConfigVariable.MinusMoney = MinusMoney;
            ConfigVariable.TotalMoney = Amount;
            new PlayStatistic(null, true).setVisible(true);
            this.dispose();
        }
        if (Count == 0) {
            Amount = 50;
            SumAmount();
        }
        btnAnswer.setEnabled(false);
        btnLeaveGame.setEnabled(false);
    }

    public void UserDoubledip() {
        buttonGroup1.clearSelection();
        if (!DoubleDip) {
            new ShowMessageDialog(null, true, "Sorry, you have the wrong answer.", "Message", ShowMessageDialog.MESSAGE);
            SetFinalInformation();
            btnAnswer.setEnabled(false);
        } else {
            lbBgA.setIcon(bgAnswer);
            lbBgB.setIcon(bgAnswer);
            lbBgC.setIcon(bgAnswer);
            lbBgD.setIcon(bgAnswer);
            rdoA.setBackground(Color.black);
            rdoB.setBackground(Color.black);
            rdoC.setBackground(Color.black);
            rdoD.setBackground(Color.black);
            DoubleDip = false;
            MinusMoney();
            btnLeaveGame.setEnabled(false);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jLabel4 = new javax.swing.JLabel();
        lbAmount = new javax.swing.JLabel();
        txtQuestion = new javax.swing.JLabel();
        lbCurrent = new javax.swing.JLabel();
        rdoD = new javax.swing.JRadioButton();
        rdoC = new javax.swing.JRadioButton();
        rdoB = new javax.swing.JRadioButton();
        rdoA = new javax.swing.JRadioButton();
        btnAnswer = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        lbName = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        lbMinusMoney = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        btnLeaveGame = new javax.swing.JButton();
        btnNext = new javax.swing.JButton();
        lbPrizeMoney = new javax.swing.JLabel();
        btnFlip = new javax.swing.JLabel();
        btnHelp5050 = new javax.swing.JLabel();
        btnDoubleDip = new javax.swing.JLabel();
        lbHelp = new javax.swing.JLabel();
        lbBgD = new javax.swing.JLabel();
        lbBgC = new javax.swing.JLabel();
        lbBgA = new javax.swing.JLabel();
        lbBgB = new javax.swing.JLabel();
        lbBgQuestion = new javax.swing.JLabel();
        lbMinus = new javax.swing.JLabel();
        lbAnswer = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        lbBackGround = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        mnSystem = new javax.swing.JMenu();
        mniConfig = new javax.swing.JMenuItem();
        mniExit = new javax.swing.JMenuItem();
        mnAbout = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        mnHelp = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(1024, 700));
        setResizable(false);
        getContentPane().setLayout(null);

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel4.setForeground(new java.awt.Color(51, 204, 0));
        jLabel4.setText("$");
        getContentPane().add(jLabel4);
        jLabel4.setBounds(690, 540, 8, 15);

        lbAmount.setFont(new java.awt.Font("Tahoma", 1, 12));
        lbAmount.setForeground(new java.awt.Color(51, 204, 0));
        lbAmount.setText("500000");
        getContentPane().add(lbAmount);
        lbAmount.setBounds(160, 540, 48, 15);

        txtQuestion.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        txtQuestion.setForeground(new java.awt.Color(51, 255, 255));
        getContentPane().add(txtQuestion);
        txtQuestion.setBounds(90, 60, 600, 50);

        lbCurrent.setFont(new java.awt.Font("Tahoma", 1, 12));
        lbCurrent.setForeground(new java.awt.Color(102, 255, 255));
        lbCurrent.setText("Current amount:");
        getContentPane().add(lbCurrent);
        lbCurrent.setBounds(50, 540, 103, 15);

        rdoD.setBackground(new java.awt.Color(0, 0, 0));
        buttonGroup1.add(rdoD);
        rdoD.setFont(new java.awt.Font("Tahoma", 0, 12));
        rdoD.setForeground(new java.awt.Color(204, 255, 255));
        rdoD.setText("Option 4");
        rdoD.setFocusable(false);
        getContentPane().add(rdoD);
        rdoD.setBounds(100, 420, 580, 23);

        rdoC.setBackground(new java.awt.Color(0, 0, 0));
        buttonGroup1.add(rdoC);
        rdoC.setFont(new java.awt.Font("Tahoma", 0, 12));
        rdoC.setForeground(new java.awt.Color(204, 255, 255));
        rdoC.setText("Option 3");
        rdoC.setFocusable(false);
        getContentPane().add(rdoC);
        rdoC.setBounds(100, 340, 580, 23);

        rdoB.setBackground(new java.awt.Color(0, 0, 0));
        buttonGroup1.add(rdoB);
        rdoB.setFont(new java.awt.Font("Tahoma", 0, 12));
        rdoB.setForeground(new java.awt.Color(204, 255, 255));
        rdoB.setText("Option 2");
        rdoB.setFocusable(false);
        getContentPane().add(rdoB);
        rdoB.setBounds(100, 260, 580, 23);

        rdoA.setBackground(new java.awt.Color(0, 0, 0));
        buttonGroup1.add(rdoA);
        rdoA.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        rdoA.setForeground(new java.awt.Color(204, 255, 255));
        rdoA.setText("Option 1");
        rdoA.setFocusable(false);
        getContentPane().add(rdoA);
        rdoA.setBounds(100, 180, 590, 23);

        btnAnswer.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/ok.png"))); // NOI18N
        btnAnswer.setText("Answer");
        btnAnswer.setFocusable(false);
        btnAnswer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAnswerActionPerformed(evt);
            }
        });
        getContentPane().add(btnAnswer);
        btnAnswer.setBounds(320, 600, 110, 40);

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/money2.png"))); // NOI18N
        getContentPane().add(jLabel2);
        jLabel2.setBounds(770, 70, 50, 60);

        lbName.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
        lbName.setForeground(new java.awt.Color(51, 255, 255));
        lbName.setText("Wellcome : ");
        lbName.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        getContentPane().add(lbName);
        lbName.setBounds(760, 40, 240, 20);

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/kbcquiz.png.png"))); // NOI18N
        getContentPane().add(jLabel1);
        jLabel1.setBounds(850, 80, 50, 50);

        jLabel7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/money1.png"))); // NOI18N
        jLabel7.setText("jLabel7");
        getContentPane().add(jLabel7);
        jLabel7.setBounds(930, 70, 60, 60);

        lbMinusMoney.setFont(new java.awt.Font("Tahoma", 1, 11));
        lbMinusMoney.setForeground(new java.awt.Color(255, 0, 0));
        lbMinusMoney.setText("0");
        getContentPane().add(lbMinusMoney);
        lbMinusMoney.setBounds(620, 540, 40, 14);

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel3.setForeground(new java.awt.Color(51, 204, 0));
        jLabel3.setText("$");
        getContentPane().add(jLabel3);
        jLabel3.setBounds(220, 540, 7, 14);

        btnLeaveGame.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/no.png"))); // NOI18N
        btnLeaveGame.setText("Leave game");
        btnLeaveGame.setFocusable(false);
        btnLeaveGame.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLeaveGameActionPerformed(evt);
            }
        });
        getContentPane().add(btnLeaveGame);
        btnLeaveGame.setBounds(600, 600, 111, 40);

        btnNext.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/ok.png"))); // NOI18N
        btnNext.setText("Next");
        btnNext.setFocusable(false);
        btnNext.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNextActionPerformed(evt);
            }
        });
        getContentPane().add(btnNext);
        btnNext.setBounds(460, 600, 110, 40);

        lbPrizeMoney.setBackground(new java.awt.Color(255, 255, 255));
        lbPrizeMoney.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/prizemoney.png"))); // NOI18N
        lbPrizeMoney.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Prize Money", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14), new java.awt.Color(255, 153, 0))); // NOI18N
        getContentPane().add(lbPrizeMoney);
        lbPrizeMoney.setBounds(750, 140, 260, 370);

        btnFlip.setFont(new java.awt.Font("Tahoma", 1, 11));
        btnFlip.setForeground(new java.awt.Color(51, 153, 0));
        btnFlip.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Gloss PNGSyncronize (Universal).png"))); // NOI18N
        btnFlip.setText("FLIP");
        btnFlip.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnFlip.setIconTextGap(2);
        btnFlip.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnFlip.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnFlipMouseClicked(evt);
            }
        });
        getContentPane().add(btnFlip);
        btnFlip.setBounds(870, 530, 24, 40);

        btnHelp5050.setFont(new java.awt.Font("Tahoma", 1, 11));
        btnHelp5050.setForeground(new java.awt.Color(51, 153, 0));
        btnHelp5050.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/5050.png"))); // NOI18N
        btnHelp5050.setText("50 : 50");
        btnHelp5050.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnHelp5050.setIconTextGap(1);
        btnHelp5050.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnHelp5050.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnHelp5050MouseClicked(evt);
            }
        });
        getContentPane().add(btnHelp5050);
        btnHelp5050.setBounds(780, 530, 37, 39);

        btnDoubleDip.setFont(new java.awt.Font("Tahoma", 1, 11));
        btnDoubleDip.setForeground(new java.awt.Color(51, 153, 0));
        btnDoubleDip.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/WLM.png"))); // NOI18N
        btnDoubleDip.setText("DOUBLE DIP");
        btnDoubleDip.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnDoubleDip.setIconTextGap(2);
        btnDoubleDip.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnDoubleDip.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnDoubleDipMouseClicked(evt);
            }
        });
        getContentPane().add(btnDoubleDip);
        btnDoubleDip.setBounds(920, 530, 66, 40);

        lbHelp.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Help", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14), new java.awt.Color(255, 153, 0))); // NOI18N
        getContentPane().add(lbHelp);
        lbHelp.setBounds(750, 510, 260, 70);

        lbBgD.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/bgAnser.png"))); // NOI18N
        getContentPane().add(lbBgD);
        lbBgD.setBounds(70, 400, 660, 70);

        lbBgC.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/bgAnser.png"))); // NOI18N
        getContentPane().add(lbBgC);
        lbBgC.setBounds(70, 320, 660, 70);

        lbBgA.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/bgAnser.png"))); // NOI18N
        getContentPane().add(lbBgA);
        lbBgA.setBounds(70, 160, 650, 70);

        lbBgB.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/bgAnser.png"))); // NOI18N
        getContentPane().add(lbBgB);
        lbBgB.setBounds(70, 240, 650, 70);

        lbBgQuestion.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbBgQuestion.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/bgQuestion.png"))); // NOI18N
        lbBgQuestion.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Question", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14), new java.awt.Color(255, 153, 0))); // NOI18N
        lbBgQuestion.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        getContentPane().add(lbBgQuestion);
        lbBgQuestion.setBounds(40, 20, 710, 120);

        lbMinus.setFont(new java.awt.Font("Tahoma", 1, 12));
        lbMinus.setForeground(new java.awt.Color(102, 255, 255));
        lbMinus.setText("Minus :");
        getContentPane().add(lbMinus);
        lbMinus.setBounds(560, 540, 60, 15);

        lbAnswer.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Answer", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14), new java.awt.Color(255, 153, 0))); // NOI18N
        getContentPane().add(lbAnswer);
        lbAnswer.setBounds(40, 140, 710, 370);

        jLabel5.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(255, 255, 255), 2, true));
        getContentPane().add(jLabel5);
        jLabel5.setBounds(550, 520, 200, 60);

        jLabel6.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(255, 255, 255), 2, true));
        getContentPane().add(jLabel6);
        jLabel6.setBounds(40, 520, 500, 60);

        jLabel8.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(204, 255, 255), 2, true));
        getContentPane().add(jLabel8);
        jLabel8.setBounds(750, 30, 260, 110);

        lbBackGround.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/background-play.jpg"))); // NOI18N
        getContentPane().add(lbBackGround);
        lbBackGround.setBounds(0, -10, 1050, 710);

        mnSystem.setText("System");

        mniConfig.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/config.png"))); // NOI18N
        mniConfig.setText("Config");
        mniConfig.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mniConfigActionPerformed(evt);
            }
        });
        mnSystem.add(mniConfig);

        mniExit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/exit.png"))); // NOI18N
        mniExit.setText("Exit");
        mniExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mniExitActionPerformed(evt);
            }
        });
        mnSystem.add(mniExit);

        jMenuBar1.add(mnSystem);

        mnAbout.setText("About");

        jMenuItem1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/about.png"))); // NOI18N
        jMenuItem1.setText("About");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        mnAbout.add(jMenuItem1);

        jMenuBar1.add(mnAbout);

        mnHelp.setText("Help");

        jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F1, 0));
        jMenuItem2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/help_copy.png"))); // NOI18N
        jMenuItem2.setText("Help");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        mnHelp.add(jMenuItem2);

        jMenuBar1.add(mnHelp);

        setJMenuBar(jMenuBar1);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnAnswerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAnswerActionPerformed
        btnNext.setEnabled(true);
        btnLeaveGame.setEnabled(false);
        if (rdoA.isSelected() == true || rdoB.isSelected() == true
                || rdoC.isSelected() == true || rdoD.isSelected() == true) {
            testChoice = true;
        } else {
            testChoice = false;
            new ShowMessageDialog(null, true, "Choice answer ?", "Message", ShowMessageDialog.MESSAGE);
            return;
        }
        new ShowMessageDialog(null, true, "Are you sure choice answer ?", "Confirmation", ShowMessageDialog.CONFIRM);
        if (ShowMessageDialog.STATUS == ShowMessageDialog.OK) {
            testAnswer = true;
            if (rdoA.getText().equals(swing.ConfigVariable.RightAnswer)) {
                lbBgA.setIcon(AnswerFalse);
                rdoA.setBackground(Color.red);
            }
            if (rdoB.getText().equals(swing.ConfigVariable.RightAnswer)) {
                lbBgB.setIcon(AnswerFalse);
                rdoB.setBackground(Color.red);
            }
            if (rdoC.getText().equals(swing.ConfigVariable.RightAnswer)) {
                lbBgC.setIcon(AnswerFalse);
                rdoC.setBackground(Color.red);
            }
            if (rdoD.getText().equals(swing.ConfigVariable.RightAnswer)) {
                lbBgD.setIcon(AnswerFalse);
                rdoD.setBackground(Color.red);
            }
            if (rdoA.isSelected() == true) {
                testChoice = true;
                if (rdoA.getText().equals(swing.ConfigVariable.RightAnswer)) {
                    RighAnswer();
                } else {
                    UserDoubledip();
                }
            }
            if (rdoB.isSelected() == true) {
                testChoice = true;
                if (rdoB.getText().equals(swing.ConfigVariable.RightAnswer)) {
                    RighAnswer();
                } else {
                    UserDoubledip();
                }
            }
            if (rdoC.isSelected() == true) {
                testChoice = true;
                if (rdoC.getText().equals(swing.ConfigVariable.RightAnswer)) {
                    RighAnswer();
                } else {
                    UserDoubledip();
                }
            }
            if (rdoD.isSelected() == true) {
                testChoice = true;
                if (rdoD.getText().equals(swing.ConfigVariable.RightAnswer)) {
                    RighAnswer();
                } else {
                    UserDoubledip();
                }
            }
        }
}//GEN-LAST:event_btnAnswerActionPerformed

    private void btnLeaveGameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLeaveGameActionPerformed
        new ShowMessageDialog(null, true, "Are you sure you want to leave game ?", "Confirmation", ShowMessageDialog.CONFIRM);
        if (ShowMessageDialog.STATUS == ShowMessageDialog.OK) {
            SetFinalInformation();
        }
}//GEN-LAST:event_btnLeaveGameActionPerformed

    private void btnDoubleDipMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnDoubleDipMouseClicked
        if (btnDoubleDip.isEnabled()) {
            new ShowMessageDialog(null, true, "<html>Are you sure you want to<br>\tuse the life line double dip ?</html>", "Confirmation", ShowMessageDialog.CONFIRM);
            if (ShowMessageDialog.STATUS == ShowMessageDialog.OK) {
                DoubleDip = true;
                btnDoubleDip.setEnabled(false);
            }
        }
}//GEN-LAST:event_btnDoubleDipMouseClicked

    private void btnHelp5050MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnHelp5050MouseClicked
        if (btnHelp5050.isEnabled()) {
            new ShowMessageDialog(null, true, "Are you sure you want to use the life line 50:50 ?", "Confirmation", ShowMessageDialog.CONFIRM);
            if (ShowMessageDialog.STATUS == ShowMessageDialog.OK) {
                Help5050();
                btnHelp5050.setEnabled(false);
            }
        }

}//GEN-LAST:event_btnHelp5050MouseClicked

    private void btnFlipMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnFlipMouseClicked
        if (Count < 13) {
            if (btnFlip.isEnabled()) {
                new ShowMessageDialog(null, true, "Are you sure you want to use the life line FLIP ?", "Confirmation", ShowMessageDialog.CONFIRM);
                if (ShowMessageDialog.STATUS == ShowMessageDialog.OK) {
                    btnAnswer.setEnabled(true);
                    buttonGroup1.clearSelection();
                    Count--;
                    LoadQuestion();
                    btnFlip.setEnabled(false);
                }
            }
            if (Count == 12) {
                new ShowMessageDialog(null, true, "You can't use help with questions 13 ", "Message", ShowMessageDialog.MESSAGE);
            }
        }
}//GEN-LAST:event_btnFlipMouseClicked

    private void btnNextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNextActionPerformed
        btnNext.setEnabled(false);
        if (Count < CountFlip) {
            lbBgA.setIcon(bgAnswer);
            lbBgB.setIcon(bgAnswer);
            lbBgC.setIcon(bgAnswer);
            lbBgD.setIcon(bgAnswer);
            btnLeaveGame.setEnabled(true);
            if (rdoA.isSelected() == true || rdoB.isSelected() == true
                    || rdoC.isSelected() == true || rdoD.isSelected() == true) {
                testChoice = true;
                btnAnswer.setEnabled(true);
                buttonGroup1.clearSelection();
                Count++;
                LoadQuestion();
            } else {
                new ShowMessageDialog(null, true, "Choice answer or choice Help ", "Message", ShowMessageDialog.MESSAGE);
                testChoice = false;
                return;
            }
        }
        // TODO add your handling code here:
    }//GEN-LAST:event_btnNextActionPerformed

    private void mniConfigActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mniConfigActionPerformed

        new Config(null, true).setVisible(true);     }//GEN-LAST:event_mniConfigActionPerformed

    private void mniExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mniExitActionPerformed

        System.exit(0);     }//GEN-LAST:event_mniExitActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        try {
            String path = new File("").getAbsolutePath() + "\\Help.chm";
            File file = new File(path);

            if (file.exists()) {
                Runtime.getRuntime().exec("rundll32 url.dll, FileProtocolHandler " + path);
            } else {
                throw new Exception("File \"Help.chm\" not found!");
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error: " + ex.getMessage(), "Notice", JOptionPane.OK_OPTION);
        }
        // TODO add your handling code here:
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        new About(null, true).setVisible(true);
    }//GEN-LAST:event_jMenuItem1ActionPerformed
    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            
//            public void run() {
//                new PlayGame().setVisible(true);
//            }
//        });
//    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAnswer;
    private javax.swing.JLabel btnDoubleDip;
    private javax.swing.JLabel btnFlip;
    private javax.swing.JLabel btnHelp5050;
    private javax.swing.JButton btnLeaveGame;
    private javax.swing.JButton btnNext;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JLabel lbAmount;
    private javax.swing.JLabel lbAnswer;
    private javax.swing.JLabel lbBackGround;
    private javax.swing.JLabel lbBgA;
    private javax.swing.JLabel lbBgB;
    private javax.swing.JLabel lbBgC;
    private javax.swing.JLabel lbBgD;
    private javax.swing.JLabel lbBgQuestion;
    private javax.swing.JLabel lbCurrent;
    private javax.swing.JLabel lbHelp;
    private javax.swing.JLabel lbMinus;
    private javax.swing.JLabel lbMinusMoney;
    private javax.swing.JLabel lbName;
    private javax.swing.JLabel lbPrizeMoney;
    private javax.swing.JMenu mnAbout;
    private javax.swing.JMenu mnHelp;
    private javax.swing.JMenu mnSystem;
    private javax.swing.JMenuItem mniConfig;
    private javax.swing.JMenuItem mniExit;
    private javax.swing.JRadioButton rdoA;
    private javax.swing.JRadioButton rdoB;
    private javax.swing.JRadioButton rdoC;
    private javax.swing.JRadioButton rdoD;
    private javax.swing.JLabel txtQuestion;
    // End of variables declaration//GEN-END:variables
}
